<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<c:set var="path" value="${pageContext.request.contextPath}" />
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>登录or注册页</title>
<!--Layui-->
<link href="${path}/layui/css/layui.css" rel="stylesheet" />

<script src="${path}/layui/layui.js"></script>
<script src="${path}/js/jquery-1.10.1.min.js"></script>

</head>
<body>
<div class="layui-tab">
  <ul class="layui-tab-title">
    <li class="layui-this">管理员登陆</li>
  </ul>
 
  <div class="layui-tab-content"style="margin-left:110px;" >
    <div class="layui-tab-item layui-show" style="margin-top:50px">
    	<form class="layui-form" >
	 		<div class="layui-form-item">
	 			<label class="layui-form-label">账号</label>
    			<div class="layui-input-inline">
      				<input type="text" name="username"lay-verify="" required  lay-verify="required|username" placeholder="请输入账号" autocomplete="off" class="layui-input">
    			</div>
	 		</div>
    
  			<div class="layui-form-item">
   				 <label class="layui-form-label">密码</label>
   					 <div class="layui-input-inline">
    			     <input type="password" name="password" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
   					 </div>
  		   </div>
 		 
    
	
 		 <div class="layui-form-item" style="margin-left:120px;">
     			 <button class="layui-btn" lay-submit lay-filter="Login_User">登录</button>
 		 </div>
 		 
		</form>	
    </div>
   
  </div>
</div>

<script>
/*切換tab,使用layer*/
 layui.use(['element','layer','form'], function(){
	  var element = layui.element;
	  var layer=layui.layer;
	  var $=layui.$;
//使用form
  var form = layui.form;

  //监听登陆提交
  form.on('submit(Login_User)', function(data){
	  $.ajax({
    		url:'${path}/action/user/adcheck',
    		type:'post',
    		data:$(data.form).serialize(),
    		dataType:'json',
    		success:function(data){
    			//layer.alert(data.msg);
    			if(data.success)
    			{
    				layer.msg(data.msg);
    				var index = parent.layer.getFrameIndex(window.name);
        			parent.layer.close(index); 
    			}
    			else
    			{
    				layer.msg(data.msg,{icon: 5});
    			}
    			
    		}
    		
    	});
  });
  
 

	 	 
//自定义验证
  form.verify({
  	  username: function(value, item){ //value：表单的值、item：表单的DOM对象
  	    if(value==""){
  	      return '用户名不能为空';
  	    }
  	    if(!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)){
  	      return '用户名不能有特殊字符';
  	    }
  	    if(/(^\_)|(\__)|(\_+$)/.test(value)){
  	      return '用户名首尾不能出现下划线\'_\'';
  	    }
  	    
  	   
  	  },
  	passwd: function(value, item){ //value：表单的值、item：表单的DOM对象
      if(value==""){
        return '密码不能为空';
      }
  	  if(/^[\S]{3,20}$/.test(value))
  	 {
          return '密码只能3~20位，且不能出现空格';

  	}
  		
    }
  	  //我们既支持上述函数式的方式，也支持下述数组的形式
  	  //数组的两个值分别代表：[正则匹配、匹配不符时的提示文字]
  	  
  	}); 
 });

</script>
</body>
</html>